Skip to content

Phase 5: metrics per output, model report plots, feature selection on the horizon error - #75

Merged
PatrickHenkel1 merged 1 commit into
refactoring_v1.0.0from
v1/phase-5-metrics
Nov 6, 2026
Merged

PatrickHenkel1 merged 1 commit into
refactoring_v1.0.0from
v1/phase-5-metrics

Conversation

@PatrickHenkel1

Copy link
Copy Markdown
Collaborator

Phase 5 of the 1.0.0 refactoring. Stacked on #74: until #74 is merged, the diff also contains Phase 4. After that merge GitHub retargets this PR to refactoring_v1.0.0 and starts the CI.

Metrics per output

  • td.metrics.by_output[output][split] holds MSE, RMSE, MAE, R² and bias (mean of prediction − truth). Previously several outputs were evaluated flattened together, mixing their units.
  • The flat keys ('RMSE Val', …) stay. With several outputs they hold the mean over the outputs.
  • HorizonMetrics additionally holds the standard deviation of the error per step.
  • Everything goes into the training data JSON.

Plots

All models now use one report (physXAI.plotting.model_report). Per output it contains:

  • True vs Predicted: small transparent points (size 3, opacity 0.3), a bold binned median per split (30 quantile bins, width 4), the IQR band and the reference diagonal.
  • Horizon error: RMSE, bias and a bias ± σ band, with the time axis in hours.
  • Further panels: the sorted predictions, the training history (including a recursive multi step training) and a metrics table per output.

Large point clouds (e.g. RNN trajectories) are thinned out to 20 000 points for display. The statistics use all values.

Plots no longer open by default. pipeline(..., plot=True) saves the report as <model>.html next to the model, or into the Logger's run folder. show_plot=True opens it, and Model.plot(td) returns the figure. Plotly is loaded from the CDN, so a report is about 70 kB, or 1.4 MB for the RNN.

Feature selection (experimental)

physXAI.feature_selection.selection.FeatureSelection replaces the old implementation:

  • Criterion: the step weighted RMSE of the recursive prediction over eval_horizon (optionally first_step_weight, plus bias_weight · |bias| at mpc_horizon). Alternatively criterion='single_step'.
  • n_repeats: every candidate is evaluated on several block splits (seeds), giving mean and spread. This shows whether differences between candidates exceed the noise.
  • controls={'oveHeaPumY_u': 1}: checks the sign of the sensitivity of the prediction to a control on the validation data. Candidates with the wrong sign are marked implausible and not selected. Controls and the recursive feature are never removed.
  • tolerance: selects the smallest input set within (1 + tolerance) × the best criterion.
  • No mutation: there are no input() prompts and the preprocessing is not changed.
  • Results: available as result.table() (DataFrame), get_config() (JSON) and plot().
  • Legacy interface: recursive_feature_elimination_pipeline remains as a wrapper and saves JSON and HTML into the run folder.

Example TAir_FeatureSelection.py (LinReg, 12 inputs, horizon 12 h, 3 block splits): the spread of the criterion across the splits (σ ≈ 0.05 K at about 0.19 K) is larger than most differences between candidates. This confirms the point that a single split and the single step error are not a reliable basis for the choice.

Tests

  • Unit tests: 125 passed, 1 skipped (RNN contract test with AgentLib main). New tests cover metrics, plots and feature selection, among them:
    • several RNN outputs are evaluated separately;
    • the binned median and the quartiles are correct;
    • the plot style;
    • HTML is saved and nothing is shown;
    • the sign check;
    • the preprocessing is not changed.
  • Executables: all executables pass the smoke run.

🤖 Generated with Claude Code

… on the horizon error

- Metrics.by_output: MSE, RMSE, MAE, R2 and bias per output and split (legacy flat keys
  kept); several outputs are no longer flattened together. HorizonMetrics adds the
  standard deviation of the error per step.
- One plot report for all models: true vs. predicted with small transparent points,
  bold binned median and IQR band per split, sorted predictions, horizon error with
  bias +- sigma band, training history (incl. multi step training), metrics table per
  output; large point clouds are thinned out for display.
- Plots are not opened by default: the pipelines save them as html next to the model,
  show_plot=True opens them; Model.plot returns the figure.
- FeatureSelection (experimental): backward elimination on the step weighted horizon
  error, repeated on several block splits, bias at the MPC horizon, sign check of the
  sensitivity to the controls, tolerance for fewer inputs; no input() prompts and no
  mutation of the preprocessing. recursive_feature_elimination_pipeline wraps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 07:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Base automatically changed from v1/phase-4-rnn to refactoring_v1.0.0 November 6, 2026 10:10
@PatrickHenkel1
PatrickHenkel1 merged commit 7b7ac44 into refactoring_v1.0.0 Nov 6, 2026
21 checks passed
@PatrickHenkel1
PatrickHenkel1 deleted the v1/phase-5-metrics branch November 6, 2026 16:28
@PatrickHenkel1 PatrickHenkel1 mentioned this pull request Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants